package component.security.hardware;


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.security.PublicKey;


import component.security.encrypt.Crypto;
import component.security.encrypt.Util;
import component.security.util.Constant;
import component.security.util.FileUtil;


/**
 * 获取硬件运行类
 *
 */
public class HardWareRunner {
	
	/**
	 * @preserve
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception{
		
		setHardWard();
		
		
		
	}
	
	/**
	 * 获取客户硬件
	 * @throws Exception
	 */
	private static void setHardWard()throws Exception{
		String key = "NetworkCard";
		
		//获取网卡
		NetWorkCardInfo netcard = new JavaNetWorkCardInfo();
		String networkCard = netcard.getMacInfo();
		
		
		//将网卡写入属性文件
		String content = key + "=" + networkCard;
		String filePath = FileUtil.getFileDir(Constant.NETWORK_CRYPTO_FILE) ;
		
		
		//用公钥对硬件信息加密
		String pubKeyFile = FileUtil.getFileDir(Constant.PUBKEY_FILE);
		PublicKey publicKey = Util.getPublicKeyFromFile(pubKeyFile);
		
		byte[] result = (new Crypto()).encrypt(content.getBytes(),publicKey);
		
		//加密文件写入文件
		FileUtil.saveObject2File(result, filePath);
		
		
		
		System.out.println("获取硬件成功！");
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		br.readLine();
	}
}
